package KK.System.IO
{
	import flash.utils.Dictionary;

	public class Input
	{
		
		static protected const KEY_RELEASE:int=-1;//弹起 
		static protected const KEY_PRESSED:int=2;//按下 
		static protected const KEY_NORMAL:int=0;//无状态 
		static protected const KEY_KEEP_PRESSED:int=1;//持续按下 
		
		
		private var _lookup:Dictionary;
		private var _map:Dictionary;
		public function Input()
		{
			_lookup=new Dictionary;
			_map=new Dictionary;
			init();
		}
		private function init():void{
			
		}
		
		/**
		 * An internal helper function used to build the key array.
		 * 
		 * @param	KeyName		String name of the key (e.g. "LEFT" or "A")
		 * @param	KeyCode		The numeric Flash code for this key.
		 */
		protected function addKey(KeyName:String,KeyCode:uint):void
		{
			_lookup[KeyName] = KeyCode;
			_map[KeyCode] = { name: KeyName, current: KEY_NORMAL, last: 0 };
		}
		
		/**
		 * Clean up memory.
		 */
		public function destroy():void
		{
			_lookup = null;
			_map = null;
		}
		
		
		
		/**
		 * check to see if this key is keep pressed 
		 * @param key
		 * @return 
		 * 
		 */
		public function keepKeyPressed(key:String):Boolean{
			return _map[_lookup[key]].current==KEY_KEEP_PRESSED;
		}
		/**
		 * check to see if this key was pressed 
		 * @param key
		 * @return 
		 * 
		 */
		public function justKeyPressed(key:String):Boolean{
			return _map[_lookup[key]].current==KEY_PRESSED;
		}
		
		/**
		 * check to see if this key was release 
		 * @param key
		 * @return 
		 * 
		 */
		public function justKeyRelease(key:String):Boolean{
			return _map[_lookup[key]].current==KEY_RELEASE;
		}
		
		/**
		 * 获取按键信息  
		 * @param key
		 * @return 
		 * 
		 */
		protected function getKeyInfo(key:String):Object{
			return _map[key];
		}
		
		
	}
}